<template>
      <view class="goods-item" @click="gotoDetail" >
        <view class="goods-item-left">
          <label class="radio" v-if="radio">
            <radio :checked="item.goods_state" color="#c00000" @click="checkedHandler"/>
          </label>
          <image :src="item.goods_small_logo||defaultPic" mode=""></image>
        </view>
        <view class="goods-item-right">
          <view class="goods-name">{{item.goods_name}}</view>
          <view class="goods-info">
            <view class="goods-price">￥{{Number(item.goods_price).toFixed(2)}}</view>
            {{cart.goods_count}}
            <uni-number-box :min="1" v-if="numBar" v-model="item.goods_count"></uni-number-box>
          </view>
        </view>
        </view>
</template>

<script>
  import {mapState,mapMutations} from 'vuex'
  export default {
    name:"my-goods",
    data() {
      return {
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    watch:{
      item:{
        deep:true,
        handler(value){
          this.saveToStorage()
        }
      } 
    },
    computed:{
      ...mapState('m_cart',['cart'])
    },
    props:{
      item:{
        type:Object,
        default:{}
      },
      radio:{
        type:Boolean,
        default:false
      },
      numBar:{
        type:Boolean,
        default:false
      }
    },
    methods:{
      ...mapMutations('m_cart',['saveToStorage']),
      gotoDetail(){
        this.$emit('click',this.item.goods_id)
      },
      checkedHandler(){
        this.$emit('change-checked',{
          goods_id:this.item.goods_id,
          goods_state:!this.item.goods_state
        })
      }
      
    }

  }
</script>

<style lang="scss">
  .goods-item{
    display: flex;
    padding: 10px 5px;
      border-bottom: 1px solid #f0f0f0;
    .goods-item-left{
      display: flex;
      align-items: center;
      margin-right: 5px;
      image{
        width: 100px;
        height: 100px;
      }
    }
    .goods-item-right{
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding-right: 5px;
      .goods-name{
        font-size: 13px;
        width:240px
      }
      .goods-info{
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        .goods-price{
          font-size: 16px;
                color: #c00000;
        }
      }
      
    }
  }

</style>